package net.ithe.filter;


import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
@Slf4j
//@WebFilter("/*")//拦截所有请求
public class DemoFilter implements Filter {
    //过滤方法，web服务启动时执行，每次请求都会执行
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        log.info("拦截到了请求……");
        //放行
        filterChain.doFilter(servletRequest,servletResponse);
    }
    //初始化方法，web服务启动时执行，只执行一次
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
       log.info("初始化过滤器");
    }
    //关闭浏览器时执行
    @Override
    public void destroy() {
        log.info("销毁过滤器");
    }
}
